<?php

namespace App\Http\Middleware;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('admin.login');
        }
    }

    public function handle($request, Closure $next, ...$guards)
    {
        if(isset($guards['0'])){
            if($guards['0'] == 'admin'){
                $request->redirectToUrl = 'admin.login';
            }else if($guards['0'] == 'user'){
                $request->redirectToUrl = 'login';
            }
        }

        $this->authenticate($request, $guards);

        return $next($request);
    }
}
